/**
 * This file is part of the FlexiTimer project.
 * 
 * Author: Florian Arndt <f.aarndt@web.de>
 *  	   Clemens Teichmann <>
 *
 * http://code.google.com/p/flexitimer/ 
 */

package flexitimer_client.calc;

import java.awt.event.ActionEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.AbstractAction;

import flexitimer_client.gui.frame;
import flexitimer_client.gui.optionFrame;

public class startTimeMinAction extends AbstractAction {

	public startTimeMinAction() {
		super("Min-Endzeit ausrechnen");
	}

	@SuppressWarnings("deprecation")
	public void actionPerformed(ActionEvent e) {
	    //SimpleDateFormat sdfa = new SimpleDateFormat("hh:mm a");
	    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
	    Date startTime = null;
	    Date maxTime = null;
	    Date workTime = null;
	 
	    try {
	    	startTime = sdf.parse(frame.getInstance().getStartTime());
	    	maxTime = sdf.parse(optionFrame.getInstance().getMinTime());
	    	workTime = sdf.parse("00:00");
	    	workTime.setHours(startTime.getHours() + maxTime.getHours());
	    	workTime.setMinutes(startTime.getMinutes() + maxTime.getMinutes());
			
			frame.getInstance().addText("Arbeitszeit minimal: "
					+ workTime.getHours() + ":" + String.format("%02d", workTime.getMinutes()) + "Uhr");
		} catch (ParseException e1) {
			frame.getInstance().addText("ERROR: Zeit falsch eingegeben! (hh:mm)");
		}
	}

}
